package util;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class enviaEmail {

	public void enviar(Exception e) {

		try {
			SimpleEmail email = new SimpleEmail();
			email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail
			email.addTo("ronefel@hotmail.com", "Rone"); // destinatário
			email.setFrom("teste@gmail.com", "Sistema CG"); // remetente
			email.setSubject("ERRO INTERNO NO SISTEMA!!!"); // assunto do e-mail

			StringWriter sw = new StringWriter();
			PrintWriter pw = new PrintWriter(sw);
			e.printStackTrace(pw);
			pw.close();
			sw.close();

			email.setMsg(sw.getBuffer().toString()); // conteudo do e-mail
			email.setAuthentication("ronegk@gmail.com", "exilimcasio");
			email.setSmtpPort(465);
			email.setSSL(true);
			email.setTLS(true);
			email.send();
		} catch (EmailException e1) {
			e1.printStackTrace();
		} catch (IOException e2) {
			e2.printStackTrace();
		}

	}

}
